<script setup lang="ts">
import { ref, reactive } from "vue";
import { searchDns } from "@/api/search/index";

defineOptions({
  name: "SearchDns"
});

const loading = ref(false);
const resultVisiable = ref(false);
const tableData = ref([]);

const queryForm = reactive({
  domain: "sina.com"
});

function onQuery() {
  loading.value = true;
  resultVisiable.value = false;
  searchDns(queryForm.domain).then(resp => {
    tableData.value = resp.data;
    console.log(resp);
    resultVisiable.value = true;
    loading.value = false;
  });
}
</script>

<template>
  <div>
    <h1>域名解析查询</h1>
    <el-form :model="queryForm">
      <el-form-item>
        <el-input
          v-model="queryForm.domain"
          placeholder="输入域名/网址一键查询"
        />
      </el-form-item>
      <el-button
        class="w-full mt-4"
        size="default"
        type="primary"
        :loading="loading"
        @click="onQuery()"
        >查询</el-button
      >
    </el-form>
    <el-divider />
    <div v-if="resultVisiable" class="result-container">
      <h3>{{ queryForm.domain }}解析结果</h3>
      <el-row v-for="(row, index) in tableData" :key="index">
        <el-divider />
        <el-row-item>
          {{ row }}
        </el-row-item>
      </el-row>
    </div>
  </div>
</template>

<style scoped>
h1,
h3 {
  margin-top: 20px;
  margin-bottom: 10px;
  text-align: center;
}
.result-container {
  padding: 5px 20px 10px;
  background-color: white;
}
</style>
